package com.example.script.admin.util;

import com.example.script.admin.enums.ResultPage;

import java.util.List;

/**
 * @author CuiZhaolong
 * @DATE 2022/2/18
 */
public class PageUtil {
    public static ResultPage listToPage(Integer pageIndex, Integer pageSize, List list, long count) {
        ResultPage.ResultPageBuilder<List> builder = ResultPage.builder();
        int totalPages = (int) (count % pageSize == 0 ? count / pageSize : (count / pageSize + 1));
        builder.pageIndex(pageIndex).pageSize(pageSize).data(list).totalPages(totalPages).totalElements(count);
        return builder.build();
    }
}
